<template>
    <div>
        <div class="container">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item class="mg">
                    发布列表
                    <el-button class="fr" type="primary" @click="massageDeliver">发布信息</el-button>
                </el-breadcrumb-item>
            </el-breadcrumb>
            <div class="handle-box">
                <span>用户名：</span><el-input v-model="query.name" placeholder="用户名称" class="handle-input mr10"></el-input>
                <span>手机号：</span><el-input v-model="query.phone" placeholder="手机号" class="handle-input mr10"></el-input>
                <span>注册时间：</span>
                <el-time-picker
                    is-range
                    v-model="query.time"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    placeholder="选择时间范围">
                </el-time-picker>
                <p class="mt">
                    <el-button type="primary" @click="handleSearch">筛选</el-button>
                    <el-button type="primary" @click="handleOut">导出</el-button>
                </p>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="id" label="标题" align="center"></el-table-column>
                <el-table-column class="height" prop="name" label="发布内容" align="center"></el-table-column>
                <el-table-column prop="address" label="发布人" align="center"></el-table-column>
                <el-table-column prop="date" label="上/下架状态" align="center"></el-table-column>
                <el-table-column prop="date" label="发布时间" align="center"></el-table-column>
                <el-table-column label="操作" align="center" width="250px">
                    <template slot-scope="scope">
                        <el-button
                        type="primary"
                        size="mini"
                        @click=" informationEdit(scope.$index, scope.row)">详情</el-button>
                        <el-button
                        type="primary"
                        size="mini"
                        @click="groundingEdit(scope.$index, scope.row)">上架</el-button>
                        <el-button
                        size="mini"
                        type="primary"
                        @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { message,serveOut,messageout } from '../../../api/index';
export default {
    name: 'basetable',
    data() {
        return {
            query: {
                address: '',
                name: '',
                pageIndex: 1,
                pageSize: 10,
                time:'',
                phone:'',
            },
            tableData: [],
            pageTotal: 0,
        };
    },
    created() {
        this.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        getData() {
            message(this.query).then(res => {
                console.log(res);
                this.tableData = res.data.list;
                this.pageTotal = res.pageTotal || 50;
            });
        },
        //发布信息
        massageDeliver(){
            console.log(11);
            this.$router.push('/Deliverifrom')
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        //导出按钮
        handleOut(){
            console.log(11);
            serveOut(this.query).then(res => {
                console.log(res);
            });
        },
        //详情操作
        informationEdit(){
            console.log(1);
            this.$router.push('/Details')
        },
        //上架操作
        groundingEdit(index,row){
            console.log(index,row);
            messageout({
                id:row.id,
                state:1,
            }).then(r=>{
                console.log(r);
            })
        },
        //编辑操作
        handleEdit(index, row) {
            console.log(index, row);
            this.$router.push('/Deliverifrom')
        },
        //分页
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 60px;
    background-color: rgb(245,245,245);
    padding: 20px 40px;
}
.handle-select {
    width: 120px;
}
>>>.el-table tbody tr{
    height: 100px;
}
.mg{
    margin: 20px 0;
}
.handle-input {
    width: 250px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.fr{
    margin-left: 1100px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.mt{
    margin-top: 20px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
